package reflection;

import annotation.Filed;
import annotation.Table;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;

/**
 * @ClassName Demo05
 * @Description TODO
 * @Author liang
 * @Date 2018/10/18 13:23
 * @Version 1.0
 **/
public class Demo05 {
    public static void main(String [] args) throws ClassNotFoundException, NoSuchFieldException {
        Class<?> clazz = Class.forName("annotation.MyStudent");
        //获得类的所有有效注解
        Annotation[] annotations = clazz.getAnnotations();
        for(Annotation a:annotations){
            System.out.println("类的注解 "+a);
        }
        //获得指定注解
        Table table = clazz.getAnnotation(Table.class);
        System.out.println(table.value());
        //获得属性注解
        Field id = clazz.getDeclaredField("id");
        Filed annotation = id.getAnnotation(Filed.class);
        System.out.println(annotation.columnName());
    }
}
